using System;
using System.Collections.Generic;
using System.Text;

namespace IntetfaceEditor4PDA
{
    public class clsFlag
    {
        public int ID;
        public string Text = "Notset";
        public override string ToString()
        {
            return Text;
        }
        public static List<clsFlag> Select()
        {
            QuerySelect query = new QuerySelect();
            query.Select(SQLControlsReader.SelectAllFlags);
            List<DataRows> rows = query.GetRows();
            List<clsFlag> list = new List<clsFlag>();
            foreach (DataRows row in rows)
            {
                clsFlag flag = new clsFlag();
                flag.ID = int.Parse(row.FieldByName("IDCHECKINGFLAG"));
                flag.Text = row.FieldByName("TEXT");
                list.Add(flag);
            }
            return list;
        }


        public static void Add(string text)
        {
            QuerySelect query = new QuerySelect();
            query.Select(SQLControlsReader.SelectGetNewIdclsFlag);
            new QueryExec().Execute(
                string.Format(SQLControlsReader.InsertclsFlag, query.GetRows()[0].FieldByNameDef("ID", "1"),
                              text.Replace("'", "''")));

        }
        public static List<clsFlag> SelectQry()
        {
            QuerySelect query = new QuerySelect();
            query.Select(SQLControlsReader.SelectAllQuery);
            List<DataRows> rows = query.GetRows();
            List<clsFlag> list = new List<clsFlag>();
            foreach (DataRows row in rows)
            {
                clsFlag flag = new clsFlag();
                flag.ID = int.Parse(row.FieldByName("IDQRYLIST"));
                flag.Text = row.FieldByName("TEXT");
                list.Add(flag);
            }
            return list;
        }

        public static void AddQry(string text)
        {
            QuerySelect query = new QuerySelect();
            query.Select(SQLControlsReader.SelectGetNewIdclsQry);
            new QueryExec().Execute(
                string.Format(SQLControlsReader.InsertQry, query.GetRows()[0].FieldByNameDef("ID", "1"),
                              text.Replace("'", "''")));
        }
    }
}
